﻿using System;
using System.Data;
using ContractManagementSystem.DataAccessLayer;
using ContractManagementSystem.EntityObjects;

namespace ContractManagementSystem.BusinessLogicLayer
{
    public static class TimesheetLogic
    {
        //Get all timesheet
        public static DataTable SelectDataTimesheet()
        {
            return TimesheetDao.SelectAllTimesheet();
        }
        //get timesheet by user name of contractor
        public static DataTable SelectDataTimesheetByUserName(string userName)
        {
            var dataTable = TimesheetDao.SelectDataTimesheetByUserName(userName);
            return dataTable;
        }
        //Get all timesheet of contractor by Client
        public static DataTable SelectDataTimesheetByClient(string userName)
        {
            var dataTable = TimesheetDao.SelectDataTimesheetByClient(userName);
            return dataTable;
        }
        //Get timesheet by consultant
        public static DataTable SelectDataTimesheetByConsultant(string user)
        {
            var dataTable = TimesheetDao.SelectDataTimesheetByConsultant(user);
            return dataTable;
        }
        //get timesheet by timesheet by id
        public static DataTable SelectTimesheetDetailByTimesheetDetailId(string timesheetId)
        {
            return TimesheetDao.SelectTimesheetDetailByTimesheetDetailId(timesheetId);
        }
        //get status timesheet by id
        public static DataTable SelectStatusTimesheet(int timesheetId)
        {
            var result = TimesheetDao.SelectStatusTimesheet(timesheetId);
            return result;
        }

        public static DataTable GetDateOfContract(string contract)
        {
            return TimesheetDao.GetDateOfContract(contract);
        }

        /// <summary>
        /// Search timesheet by Contract Title, 
        /// </summary>
        /// <param name="contractNumber"></param>
        /// <param name="timesheetStatus"></param>
        /// <param name="fromDate"></param>
        /// <param name="toDate"></param>
        /// <param name="sort"></param>
        /// <returns></returns>
        public static DataTable SearchTimesheet(string contractNumber, string timesheetStatus, string fromDate, string toDate, string sort)
        {
            var result = TimesheetDao.SearchTimesheet(contractNumber, timesheetStatus, fromDate, toDate, sort);
            return result;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="contractNumber"></param>
        /// <param name="timesheetStatus"></param>
        /// <param name="fromDate"></param>
        /// <param name="toDate"></param>
        /// <param name="sort"></param>
        /// <param name="userName"></param>
        /// <returns></returns>
        public static DataTable SearchTimesheetByUserName(string contractNumber, string timesheetStatus,string fromDate, string toDate, string sort, string userName)
        {
            var result = TimesheetDao.SearchTimesheetByUserName(contractNumber, timesheetStatus, fromDate, toDate, sort,
                                                                userName);
            return result;
        }
        public static DataTable SearchTimesheetByConsultant(string contractNumber, string timesheetStatus,string fromDate, string toDate, string sort, string userName)
        {
            var result = TimesheetDao.SearchTimesheetByConsultant(contractNumber, timesheetStatus, fromDate, toDate, sort,
                                                                userName);
            return result;
        }
        /// <summary>
        /// Sort timesheet by ondate, status, contract
        /// </summary>
        /// <param name="sortBy"></param>
        /// <returns></returns>
        public static DataTable SortTimesheet(string sortBy)
        {
            var result = TimesheetDao.SortTimesheet(sortBy);
            return result;
        }
        public static DataTable FilterApproveTimesheet(TimesheetDetailEntity timesheetDetailEntity)
        {
            var result = TimesheetDao.FilterApproveTimesheet(timesheetDetailEntity);
            return result;
        }
        public static DataTable FilterApproveTimesheetByClient(string client, TimesheetDetailEntity timesheetDetailEntity)
        {
            var result = TimesheetDao.FilterApproveTimesheetByClient(client, timesheetDetailEntity);
            return result;
        }

        #region"Insert/ delete/ update"
        //insert timesheet
        public static string InsertTimesheet(TimesheetDetailEntity timesheet)
        {
            if(timesheet.Time> 24 || timesheet.Time <1 )
            {
                return null;
            }
            return TimesheetDao.InsertTimesheet(timesheet);
        }
        //update tiemsheet
        public static string UpdateTimesheet(TimesheetDetailEntity timesheetDetail)
        {
            return TimesheetDao.UpdateTimesheet(timesheetDetail);
        }
        //delete timesheet 
        public static string DeleteTimesheet(TimesheetDetailEntity timesheet)
        {
            return TimesheetDao.DeleteTimesheet(timesheet);
        }

        #endregion

        #region "Approve Timesheet"

        public static DataTable SelectReasonById(int timesheetId)
        {
            var result = TimesheetDao.SelectReasonById(timesheetId);
            return result;
        }

        public static string ApproveTimesheet(TimesheetDetailEntity timesheetDetailEntity)
        {
            return TimesheetDao.ApproveTimesheet(timesheetDetailEntity);
        }

        public static string UpdateReason(TimesheetDetailEntity timesheetDetail)
        {
            if(timesheetDetail.Reason==null)
            {
                return null;
            }
            string reason = TimesheetDao.UpdateReason(timesheetDetail);
            return reason;
        }

        #endregion
    }
}
